import {createRouter, createWebHistory} from 'vue-router'


const routes = [
    {
        path: '/home',
        name: 'Home',
        component: () => import('@/pages/index.vue'),
        meta: {
            title: '首页'
        },
        children: [
            {
                path: 'linkman', component: () => import('@/pages/index/linkman.vue'), children: [
                    {path: 'inform', component: () => import('@/pages/linkman/inform.vue')},
                    {path: 'user', component: () => import('@/pages/linkman/user.vue')},
                ]
            },
            {path: 'message', component: () => import('@/pages/index/message.vue')},
            {path: 'space', component: () => import('@/pages/index/space.vue'),children: [
                {path: 'all', component: () => import('@/pages/space/all.vue')},
                {path: 'friends', component: () => import('@/pages/space/friends.vue')},
                // {path:'/', redirect: '/space/all'}
            ]},
            {path: 'video', component: () => import('@/pages/index/video.vue')},
            {path: 'my', component: () => import('@/pages/index/my.vue')},
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/pages/login.vue')
    },
    {
        path: '/resetPassword',
        name: 'ResetPassword',
        component: () => import('@/pages/resetPassword.vue')
    },
    {
        path: '/Talk',
        name: 'Talk',
        component: () => import('@/pages/Talk.vue')
    },
    {
        path: '/wode',
        name: 'Wode',
        component: () => import('@/pages/Wode.vue')
    },
    {
        path: '/twocode',
        name: 'TwoCode',
        component: () => import('@/pages/Twocode.vue')
    },
    {
        path: '/video',
        name: 'Video',
        component: () => import('@/pages/video.vue')
    },
    {
        path: '/test',
        name: 'Test',
        component: () => import('@/pages/test.vue')
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path !== '/login') {
        if (localStorage.getItem('user')) {
            next()
        }
        next('/login')
    } else {
        next()
    }
})
export default router